{% load staticfiles %}
{% csrf_token %}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="{% static 'css/demo.css' %}">
        <link rel="stylesheet" href="{% static 'css/metroStyle/metroStyle.css' %}">
        <link rel="stylesheet" href="{% static 'css/layui.css' %}">
        <link rel="stylesheet" href="{% static 'css/index.css' %}">
        <title>编写yaml</title>
    </head>
    <body id="yss_all">
        <div class="layui-yaml" style="height: 95%;">
            <div class="layui-tab" lay-filter="yamltab">
                <ul class="layui-tab-title">
                    <li class="layui-this">Yml编写</li>
                    <li id="yamllist">Yml展示</li>
                    <li id="yamlrules">rules编写</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form id="formall" name="formall" class="layui-form">
                            <div class="layui-yaml-left">
                                <div class="layui-form-item">
                                    <div class="layui-input-block layui-input-block-yaml">
                                        <textarea id="yaml" name="yaml" required lay-verify="required" placeholder="YAML内容" class="layui-textarea layui-textarea-yaml layui-all-hw"></textarea>
                                        <div class="layui-yaml-button">
                                            <button id="tojson" type="button" class="layui-btn layui-btn-sm  layui-btn-danger" onclick="jsonyamlconvert('tojson')">
                                                转<i class="layui-icon">&#xe602;</i>
                                            </button><br><br><br><br>
                                            <button type="button" class="layui-btn layui-btn-sm layui-btn-warm" onclick="jsonyamlconvert('toyaml')">
                                                <i class="layui-icon">&#xe603;</i>转
                                            </button>
                                        </div>
                                        <textarea id="json" name="json" placeholder="JSON内容" class="layui-textarea layui-textarea-yaml layui-all-hw" disabled></textarea>
{#                                        disabled#}
                                    </div>
                                </div>
                            </div>
                            <div class="layui-yaml-right">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">YAML名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="title" required lay-verify="required" lay-verify="title" autocomplete="off" placeholder="请输入名称" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">描述</label>
                                    <div class="layui-input-block">
                                        <textarea name="describe" placeholder="请输入内容" class="layui-textarea" ></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button type="button" id="submitde" class="layui-btn" lay-submit lay-filter="submitde">提交</button>
                                        <button id="resets" type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item" >
                        <div id="ysstable" class="layui-form-ysstable">
                            <table class="layui-table" id="yaml_list_ply" lay-filter="yaml_list_ply"></table>
                        </div>
                        <div class="layui-form-textarea-check">
                            <textarea id="yamlcheck" name="yamlcheck" placeholder="YAML展示" class="layui-textarea" style="margin: 22px 0 0 0; height: 90%;" disabled></textarea>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-rules-left">
                            <div class="rules-left-button">
                                <div style="font-size:20px ;position: relative;top:50%;transform: translateY(-50%);"><label >Rules展示</label></div>
{#                                <span title="创建角色或目录">#}
{#                                    <button type="button" class="layui-btn" id="createrule">#}
{#                                        <i class="layui-icon">&#xe7a0;</i>#}
{#                                    </button>#}
{#                                </span>#}
{#                                <span title="创建文件">#}
{#                                    <button type="button" class="layui-btn" id="createfile">#}
{#                                        <i class="layui-icon">&#xe61d;</i>#}
{#                                    </button>#}
{#                                </span>#}
                                <span title="上传文件">
                                    <button type="button" class="layui-btn" id="rulesupload" style="float: right; margin-top: -5px;">
                                        <i class="layui-icon">&#xe67c;</i>
                                    </button>
                                </span>
                            </div>
                            <hr class="layui-bg-cyan" style="margin:0;">
                            <div class="rules-left-tree">
{#                                <ul id="rulestree"></ul>#}
                                <ul id="treeDemo" class="ztree"></ul>
                            </div>
                        </div>
                        <div class="layui-rules-right">
                            <div class="layui-rules-data">
                                <div style="height: 80px; margin-top:-10px;">
                                    <button type="button" id="checkfile" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-file" lay-submit lay-filter="checkfile">查看</button>
                                    <button type="button" id="submitfile" class="layui-btn layui-btn-radius layui-btn-warm layui-btn-file" lay-submit lay-filter="submitfile">修改</button>
                                    <button type="button" id="submitdata" class="layui-btn layui-btn-radius layui-btn-danger layui-btn-file" lay-submit lay-filter="submitdata" style="display:none">提交</button>
                                    <button type="button" id="cancelsubmit" class="layui-btn layui-btn-radius layui-btn-file" lay-submit lay-filter="submitdata" style="display:none">取消</button>
                                </div>
                                <textarea id="filedata" name="filedata" placeholder="文件内容" class="layui-textarea layui-textarea-data" disabled></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script type="text/html" id="yamlDemo">
            <a class="layui-btn layui-btn-xs" lay-event="check">查看</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="{% static 'layui.all.js' %}"></script>
    <script src="{% static 'js/automation/json2yaml.js' %}"></script>
    <script src="{% static 'js/automation/yaml2json.js' %}"></script>


    <script type="text/javascript">
        layui.config({
            base: 'lib/' //假设这是test.js所在的目录
        });
        function jsonyamlconvert(type){
            var json, yml, data;
            if(type === "toyaml"){
                json = document.getElementById("json").value;
                try {
                    data = JSON.parse(json)
                } catch (e) {
                    document.getElementById("yaml").value = "convert Error, check your data please.";
                    return;
                }
                yml = YAML.stringify(data,4,4);
                document.getElementById("yaml").value = yml;
            } else if(type === "tojson"){
                yml = document.getElementById("yaml").value;
                try {
                    data = YAML.parse(yml)
                } catch (e) {
                    document.getElementById("json").value = "convert Error, check your data please.";
                    return;
                }
                json = JSON.stringify(data, null, "  ");
                document.getElementById("json").value = json;
            }
        }
    </script>
    <script src="{% static 'js/automation/yamleditor.js' %}"></script>

</html>